#define _CRT_SECURE_NO_WARNINGS
//bfs
class Solution {
public:
    int maxDepth(TreeNode* root) {
        int depth = 0;
        if (root == nullptr) return 0;
        queue<TreeNode*> st;
        st.push(root);
        while (!st.empty()) {
            depth++;
            int size = st.size();
            for (int i = 0; i < size; i++) {
                TreeNode* node = st.front();
                st.pop();
                if (node->left) st.push(node->left);
                if (node->right) st.push(node->right);
            }
        }
        return depth;
    }
};
//dfs
class Solution {
public:
    int maxDepth(TreeNode* root) {
        return dfs(root);
    }
    int dfs(TreeNode* root) {
        if (root == nullptr) return 0;
        int left = dfs(root->left);
        int right = dfs(root->right);
        return max(left, right) + 1;
    }
};